# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=crt
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
replaces="${MINGW_PACKAGE_PREFIX}-${_realname}-svn"
_ver_base=4.0.0
pkgver=4.0.0.4063.a24fb0f
pkgrel=1
pkgdesc='MinGW-w64 CRT for Windows'
arch=('any')
url='http://mingw-w64.sourceforge.net'
license=('custom')
groups=("${MINGW_PACKAGE_PREFIX}-toolchain" "${MINGW_PACKAGE_PREFIX}")
depends=("${MINGW_PACKAGE_PREFIX}-headers-git")
makedepends=("git" "${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-binutils")
provides=("${MINGW_PACKAGE_PREFIX}-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-${_realname}")
options=('!strip' 'staticlibs' '!buildflags' '!emptydirs')
source=("${_realname}"::"git://git.code.sf.net/p/mingw-w64/mingw-w64")
md5sums=('SKIP')

pkgver() {
  cd "$srcdir/${_realname}"
  printf "%s.%s.%s" "$_ver_base" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
  cd ${srcdir}/${_realname}
}

build() {
  msg "Building ${MINGW_CHOST} CRT"
  case "$CARCH" in
    i686)
      _crt_configure_args="--disable-lib64 --enable-lib32"
    ;;
    x86_64)
      _crt_configure_args="--disable-lib32 --enable-lib64"
    ;;
  esac
  mkdir -p ${srcdir}/crt-${MINGW_CHOST} && cd ${srcdir}/crt-${MINGW_CHOST}
  ${srcdir}/${_realname}/mingw-w64-crt/configure \
    --prefix=${MINGW_PREFIX}/${MINGW_CHOST} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --with-sysroot=${MINGW_PREFIX}/${MINGW_CHOST} \
    --enable-wildcard \
    ${_crt_configure_args}
  make
}

package() {
  msg "Installing ${MINGW_CHOST} crt"
  cd ${srcdir}/crt-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install-strip
}

